﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Work2
    {
        //static void Main()
        //{
        //    Console.WriteLine("{0,-10} {1,-10} {2,-30} {3,-30}", "类型", "字节数", "最小值", "最大值");
        //    Console.WriteLine(new string('-', 90));

        //    PrintTypeInfo<sbyte>("sbyte");
        //    PrintTypeInfo<byte>("byte");
        //    PrintTypeInfo<short>("short");
        //    PrintTypeInfo<ushort>("ushort");
        //    PrintTypeInfo<int>("int");
        //    PrintTypeInfo<uint>("uint");
        //    PrintTypeInfo<long>("long");
        //    PrintTypeInfo<ulong>("ulong");
        //    PrintTypeInfo<float>("float");
        //    PrintTypeInfo<double>("double");
        //    PrintTypeInfo<decimal>("decimal");
        //}
        static void PrintTypeInfo<T>(string typeName) where T : struct, IComparable
        {
            int size = System.Runtime.InteropServices.Marshal.SizeOf(typeof(T));
            string min = "";
            string max = "";

            if (typeof(T) == typeof(sbyte))
            {
                min = sbyte.MinValue.ToString();
                max = sbyte.MaxValue.ToString();
            }
            else if (typeof(T) == typeof(byte))
            {
                min = byte.MinValue.ToString();
                max = byte.MaxValue.ToString();
            }
            else if (typeof(T) == typeof(short))
            {
                min = short.MinValue.ToString();
                max = short.MaxValue.ToString();
            }
            else if (typeof(T) == typeof(ushort))
            {
                min = ushort.MinValue.ToString();
                max = ushort.MaxValue.ToString();
            }
            else if (typeof(T) == typeof(int))
            {
                min = int.MinValue.ToString();
                max = int.MaxValue.ToString();
            }
            else if (typeof(T) == typeof(uint))
            {
                min = uint.MinValue.ToString();
                max = uint.MaxValue.ToString();
            }
            else if (typeof(T) == typeof(long))
            {
                min = long.MinValue.ToString();
                max = long.MaxValue.ToString();
            }
            else if (typeof(T) == typeof(ulong))
            {
                min = ulong.MinValue.ToString();
                max = ulong.MaxValue.ToString();
            }
            else if (typeof(T) == typeof(float))
            {
                min = float.MinValue.ToString("G9");
                max = float.MaxValue.ToString("G9");
            }
            else if (typeof(T) == typeof(double))
            {
                min = double.MinValue.ToString("G17");
                max = double.MaxValue.ToString("G17");
            }
            else if (typeof(T) == typeof(decimal))
            {
                min = decimal.MinValue.ToString();
                max = decimal.MaxValue.ToString();
            }

            Console.WriteLine("{0,-10} {1,-10} {2,-30} {3,-30}", typeName, size, min, max);
        }
    }

}
